package model

import (
	"time"
)

// RecordingStatus 录音状态
type RecordingStatus string

const (
	RecordingStatusPending   RecordingStatus = "pending"   // 等待中
	RecordingStatusActive    RecordingStatus = "active"    // 录制中
	RecordingStatusCompleted RecordingStatus = "completed" // 已完成
	RecordingStatusFailed    RecordingStatus = "failed"    // 失败
	RecordingStatusArchived  RecordingStatus = "archived"  // 已归档
)

// RecordingType 录音类型
type RecordingType string

const (
	RecordingTypeAutomatic RecordingType = "automatic" // 自动录音
	RecordingTypeManual    RecordingType = "manual"    // 手动录音
	RecordingTypeOnDemand  RecordingType = "ondemand"  // 按需录音
)

// RecordingFormat 录音格式
type RecordingFormat string

const (
	RecordingFormatWAV  RecordingFormat = "wav"  // WAV格式
	RecordingFormatMP3  RecordingFormat = "mp3"  // MP3格式
	RecordingFormatOGG  RecordingFormat = "ogg"  // OGG格式
)

// Recording 录音记录
type Recording struct {
	ID           string          `json:"id" bson:"_id"`
	CallID       string          `json:"call_id" bson:"call_id"`
	AgentID      string          `json:"agent_id" bson:"agent_id"`
	CustomerID   string          `json:"customer_id" bson:"customer_id"`
	PhoneNumber  string          `json:"phone_number" bson:"phone_number"`
	Direction    string          `json:"direction" bson:"direction"` // inbound/outbound
	StartTime    time.Time       `json:"start_time" bson:"start_time"`
	EndTime      time.Time       `json:"end_time" bson:"end_time"`
	Duration     int64           `json:"duration" bson:"duration"` // 秒
	Status       RecordingStatus `json:"status" bson:"status"`
	Type         RecordingType   `json:"type" bson:"type"`
	Format       RecordingFormat `json:"format" bson:"format"`
	FilePath     string          `json:"file_path" bson:"file_path"`
	FileSize     int64           `json:"file_size" bson:"file_size"` // 字节
	QualityScore float64         `json:"quality_score" bson:"quality_score"`
	IsEncrypted  bool            `json:"is_encrypted" bson:"is_encrypted"`
	IsArchived   bool            `json:"is_archived" bson:"is_archived"`
	ArchivePath  string          `json:"archive_path" bson:"archive_path"`
	Metadata     map[string]interface{} `json:"metadata" bson:"metadata"`
	CreatedAt    time.Time       `json:"created_at" bson:"created_at"`
	UpdatedAt    time.Time       `json:"updated_at" bson:"updated_at"`
}

// QualityCheckStatus 质检状态
type QualityCheckStatus string

const (
	QualityCheckStatusPending  QualityCheckStatus = "pending"  // 等待质检
	QualityCheckStatusInProgress QualityCheckStatus = "in_progress" // 质检中
	QualityCheckStatusCompleted QualityCheckStatus = "completed" // 已完成
	QualityCheckStatusRejected QualityCheckStatus = "rejected" // 已拒绝
)

// QualityRule 质检规则
type QualityRule struct {
	ID          string    `json:"id" bson:"_id"`
	Name        string    `json:"name" bson:"name"`
	Description string    `json:"description" bson:"description"`
	Weight      float64   `json:"weight" bson:"weight"` // 权重
	Question    string    `json:"question" bson:"question"`
	Options     []string  `json:"options" bson:"options"`
	Scores      []float64 `json:"scores" bson:"scores"`
	IsRequired  bool      `json:"is_required" bson:"is_required"`
	CreatedAt   time.Time `json:"created_at" bson:"created_at"`
	UpdatedAt   time.Time `json:"updated_at" bson:"updated_at"`
}

// QualityTemplate 质检模板
type QualityTemplate struct {
	ID          string        `json:"id" bson:"_id"`
	Name        string        `json:"name" bson:"name"`
	Description string        `json:"description" bson:"description"`
	Rules       []QualityRule `json:"rules" bson:"rules"`
	IsDefault   bool          `json:"is_default" bson:"is_default"`
	CreatedAt   time.Time     `json:"created_at" bson:"created_at"`
	UpdatedAt   time.Time     `json:"updated_at" bson:"updated_at"`
}

// QualityCheck 质检记录
type QualityCheck struct {
	ID            string            `json:"id" bson:"_id"`
	RecordingID   string            `json:"recording_id" bson:"recording_id"`
	Recording     *Recording        `json:"recording,omitempty" bson:"-"`
	CheckerID     string            `json:"checker_id" bson:"checker_id"`
	CheckerName   string            `json:"checker_name" bson:"checker_name"`
	TemplateID    string            `json:"template_id" bson:"template_id"`
	Template      *QualityTemplate  `json:"template,omitempty" bson:"-"`
	TotalScore    float64           `json:"total_score" bson:"total_score"`
	Status        QualityCheckStatus `json:"status" bson:"status"`
	Comments      string            `json:"comments" bson:"comments"`
	Suggestions   string            `json:"suggestions" bson:"suggestions"`
	RuleResponses []RuleResponse    `json:"rule_responses" bson:"rule_responses"`
	CreatedAt     time.Time         `json:"created_at" bson:"created_at"`
	UpdatedAt     time.Time         `json:"updated_at" bson:"updated_at"`
	CompletedAt   time.Time         `json:"completed_at" bson:"completed_at"`
}

// RuleResponse 规则响应
type RuleResponse struct {
	RuleID    string  `json:"rule_id" bson:"rule_id"`
	RuleName  string  `json:"rule_name" bson:"rule_name"`
	Option    string  `json:"option" bson:"option"`
	Score     float64 `json:"score" bson:"score"`
	Comment   string  `json:"comment" bson:"comment"`
}

// QualityCheckTask 质检任务
type QualityCheckTask struct {
	ID            string            `json:"id" bson:"_id"`
	RecordingID   string            `json:"recording_id" bson:"recording_id"`
	AssignedToID  string            `json:"assigned_to_id" bson:"assigned_to_id"`
	AssignedToName string           `json:"assigned_to_name" bson:"assigned_to_name"`
	AssignedByID  string            `json:"assigned_by_id" bson:"assigned_by_id"`
	AssignedByName string           `json:"assigned_by_name" bson:"assigned_by_name"`
	Status        QualityCheckStatus `json:"status" bson:"status"`
	Deadline      time.Time         `json:"deadline" bson:"deadline"`
	Priority      int               `json:"priority" bson:"priority"` // 1-5
	CreatedAt     time.Time         `json:"created_at" bson:"created_at"`
	UpdatedAt     time.Time         `json:"updated_at" bson:"updated_at"`
}

// RecordingSearchCriteria 录音搜索条件
type RecordingSearchCriteria struct {
	AgentID      string    `json:"agent_id" form:"agent_id"`
	CustomerID   string    `json:"customer_id" form:"customer_id"`
	PhoneNumber  string    `json:"phone_number" form:"phone_number"`
	Direction    string    `json:"direction" form:"direction"`
	Status       string    `json:"status" form:"status"`
	Type         string    `json:"type" form:"type"`
	StartDate    time.Time `json:"start_date" form:"start_date"`
	EndDate      time.Time `json:"end_date" form:"end_date"`
	MinDuration  int64     `json:"min_duration" form:"min_duration"`
	MaxDuration  int64     `json:"max_duration" form:"max_duration"`
	Page         int       `json:"page" form:"page"`
	PageSize     int       `json:"page_size" form:"page_size"`
}